var { SERVER_URL } = require('../../comm/script/config')
var config = require('../../comm/script/config')
var url = 'https://douban-api.uieee.com/v2/movie/top250'
var searchByTagUrl = 'https://douban-api.uieee.com/v2/movie/search?tag='
Page({
	data: {
		films: [],
		hasMore: true,
		showLoading: true,
		start: 0,
		windowHeight: 0
	},
	onLoad: function() {
		var that = this
		wx.request({
			url: SERVER_URL + '/api/movies/top-rated',
			method: 'GET',
			success: function(res) {
				that.setData({
					films: res.data,
					showLoading: false
				});
			},
			fail: function() {
				that.setData({
					showLoading: false
				});
			}
		});
	},
	onShow: function() {
		var that = this
		const windowInfo = wx.getWindowInfo()
		that.setData({
			windowHeight: windowInfo.windowHeight * 2
		})
	},
	scroll: function(e) {
		console.log(e)
	},
	scrolltolower: function() {},
	viewFilmDetail: function(e) {
		var id = e.detail.id;
		wx.navigateTo({
			url: "../filmDetail/filmDetail?id=" + id
		})
	},
	onPullDownRefresh: function() {
		var that = this
		wx.request({
			url: SERVER_URL + '/api/movies/top-rated',
			method: 'GET',
			success: function(res) {
				that.setData({
					films: res.data,
					hasMore: false,
					showLoading: false,
					start: 0
				});
			},
			fail: function() {
				that.setData({
					showLoading: false
				});
			}
		});
	},
	viewFilmByTag: function(e) {
		var data = e.currentTarget.dataset
		var keyword = data.tag
		wx.navigateTo({
			url: '../searchResult/searchResult?url=' + encodeURIComponent('https://douban-api.uieee.com/v2/movie/search?tag=') + '&keyword=' + keyword
		})
	}
})